//
//  JCCNetworking.h
//  test
//
//  Created by jcc on 16/7/1.
//  Copyright © 2016年 jcc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@class NSURLSessionTask;

/*!
 *  下载进度
 *
 *  @param bytesRead                 已下载的大小
 *  @param totalBytesRead            文件总大小
 *
 */
typedef void (^JCCDownloadProgress)(int64_t bytesRead,
                                    int64_t totalBytesRead);
// 请勿直接使用NSURLSessionDataTask,以减少对第三方的依赖
// 所有接口返回的类型都是基类NSURLSessionTask，若要接收返回值
// 且处理，请转换成对应的子类类型
typedef NSURLSessionTask JCCURLSessionTask;
typedef void(^JCCResponseSuccess)(id response);
typedef void(^JCCResponseFail)(NSError *error);

@interface JCCNetworking : NSObject

+ (JCCNetworking *)shareInstance;

+ (void)setBaseUrl:(NSString *)baseUrl;
+ (NSString *)baseUrl;
/**
 *
 *  请求接口，若不指定baseurl，可传完整的url
 *
 *  @param url     接口路径，如/path/getArticleList
 *  @param params  接口中所需的参数，如@{"categoryid" : @(12)}
 *  @param success 接口成功请求到数据的回调
 *  @param fail    接口请求数据失败的回调
 *
 *  @return return value description
 */
+ (JCCURLSessionTask *)getWithUrl: (NSString *)url
                           params: (NSDictionary *)params
                          success: (JCCResponseSuccess)success
                             fail: (JCCResponseFail)fail;
+ (JCCURLSessionTask *)postWithUrl: (NSString *)url
                            params: (NSDictionary *)params
                           success: (JCCResponseSuccess)success
                              fail: (JCCResponseFail)fail;
+ (JCCURLSessionTask *)downLoadUrl: (NSString *)url
                          savePath: (NSString *)path
                          progress:(JCCDownloadProgress)progressBlock
                           success:(JCCResponseSuccess)success
                           failure:(JCCResponseFail)failure;
@end
